
axios.defaults.baseURL = 'http://124.223.14.236:8060/admin'

// http://124.223.14.236:8060/admin//index/login
// axios.post(`/index/login`, {
//   login_name: 'admin',
//   password:'111111'
// }).then(res => {
//   // console.log(res);
//   // console.log(res.data.data.token);
//   localStorage.setItem('token',res.data.data.token)

// })

axios.interceptors.request.use(config => {
 //indexof 来判断（）内的内容出现在第几个下标 ，-1是指没有
   config.headers['x-token'] = localStorage.getItem('token')
  //  config.headers.Authorization = localStorage.getItem('token')
 

 return config;
}, error => {
 return Promise.reject(error);
});
// 响应拦截器 响应时若身份没有认证成功跳转到登录页面
axios.interceptors.response.use(response => {
  // console.log(response);
    //控制访问权限
 if (response.data.status === 1 && response.data.message === '身份认证失败！') {
   location.href = '/youdianda_static/index.html'
    // localStorage.removeItem('token')
 }
 return response;
}, error => {
 return Promise.reject(error);
});